package cn.jhc.test;

import java.util.List;

import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cn.jhc.model.Goods;
import cn.jhc.model.ShopCar;
import cn.jhc.model.User;
import cn.jhc.service.GoodsService;
import cn.jhc.service.ShopCarService;
import cn.jhc.service.UserService;

public class test {

	@Test
	public void testuser() {
		
				ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
				UserService service = (UserService)ac.getBean("userService");
				User user= new User();
                user.setId(3);
                user.setUsername("heshuai");
                user.setPassword("password");
//				service.addUser(user);
//				service.removeUser(user);
				List<User>list=service.findAllUser();
				for(int i=0;i<list.size();i++){
					System.out.println(list.get(i).getId()+" "+list.get(i).getPassword()+" "+list.get(i).getUsername());
					
				};
//               System.out.println(service.findUserById(4).getUsername());
//                service.updateUser(user);
			}
		

	@Test
	public void testgoods() {
		
				ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
				GoodsService goodservice = (GoodsService)ac.getBean("goodsService");
				Goods goods = new Goods();
                goods.setGoodname("heshuai");
                goods.setPrice("price");
                goods.setDiscount("discount");
                goods.setImg("img");
                goods.setGoodbn("2");
              goodservice.addGood(goods);
//              System.out.println(goodservice.findGoodById(5).getGoodname());  
//              goodservice.removeGood(2);
//              goodservice.updateGood(goods);
			}
	@Test
	public void testshopcar() {
		
				ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
				ShopCarService shopcarservice = (ShopCarService) ac.getBean("shopCarService");
				ShopCar shopCar = new ShopCar();
				shopCar.setId(1);
				shopCar.setGoodname("name");
				shopCar.setPrice("price");
				shopCar.setDisount("disount");
				shopCar.setImg("img");
				shopCar.setQuantity("quantity");
				shopCar.setTotal("total");
				shopcarservice.addshopcar(shopCar);
//				shopcarservice.removeshopcar(shopCar);
//				shopcarservice.updateGood(shopCar);
//				System.out.println(shopcarservice.findshopCarById(2).getGoodname());
			}
	}


